package com.gitee.springioc.service.impl;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;

/**
 * @author ming.yan-1
 * @version V1.0
 * @Title com.gitee.springioc.service.impl
 * @Description
 * @date 2018/9/14  下午2:44
 */
public class OrderInitializingBean implements InitializingBean,ApplicationContextAware{

    private ApplicationContext applicationContext;

    public static final Log logger = LogFactory.getLog(OrderInitializingBean.class);
    @Override
    public void afterPropertiesSet() throws Exception {
//        BeanDefinitionRegistry beanRegistry = (BeanDefinitionRegistry) applicationContext;
//        applicationContext.containsBean("PayService");
//        AbstractBeanDefinition beanDefinition =(AbstractBeanDefinition)beanRegistry.getBeanDefinition("PayService");
//        AbstractBeanDefinition newBeanDefinition = beanDefinition.cloneBeanDefinition();
//        //如果beanFactory已经开始注册Bean了则只是加到bean names map里，等beanFactory.getBean()时发起Bean加载，
//        //如果BeanFactory未开始注册，则会进行正常注册。
//        beanRegistry.registerBeanDefinition("PayServiceSelf",newBeanDefinition);
        logger.info("into OrderInitializingBean afterPropertiesSet method ");
    }

    /**
     * 回调设置applicationContext
     * @param applicationContext
     * @throws BeansException
     */
    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        this.applicationContext = applicationContext;
    }
}
